package com.vipheyue.huaxue.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.orhanobut.logger.Logger;
import com.vipheyue.huaxue.R;
import com.vipheyue.huaxue.activity.TypeActivity;
import com.vipheyue.huaxue.adapter.BaseRecyclerAdapter;
import com.vipheyue.huaxue.adapter.BaseRecyclerViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class BrowseMenuRightFragment extends Fragment {

    @Bind(R.id.recyclerView)
    RecyclerView recyclerView;
    private List<String> mdata = new ArrayList<String>();
    private BaseRecyclerAdapter adapter;
    private int argInt;

    public BrowseMenuRightFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_browse_menu_right, container, false);
        ButterKnife.bind(this, view);
        initview();
        Bundle bundle = getArguments();
        try {
            argInt = bundle.getInt("argInt");
        } catch (Exception e) {
            argInt = 0;
        }
        initData();
        return view;
    }

    private void initData() {
        switch (argInt) {
            case 0:
                mdata.clear();
                mdata.add("规范性文件");
                mdata.add("反措文件");
                mdata.add("验收文件");
                mdata.add("说明书");
                mdata.add("各类信息");
                break;
            case 1:
                mdata.clear();
                mdata.add("作业风险评估与防范");
                mdata.add("消缺经验");
                mdata.add("特殊设备特殊经验");
                mdata.add("部门经验库");
                break;
            case 2:
                mdata.clear();
                mdata.add("手艺示范");
                mdata.add("工器具使用");
                mdata.add("继电保护");
                mdata.add("自动化");
                mdata.add("新技术");
                break;
            case 3:
                mdata.clear();
                mdata.add("工作备忘");
                mdata.add("老员工经验谈");
                mdata.add("安全事故学习");
                mdata.add("社区问答");
                break;
        }
        adapter.notifyDataSetChanged();

    }

    private void initview() {
        GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), 2);
//        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);//设置显示方式
//        recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this)//第三
//                .drawable(R.drawable.divider)//这里可以是图片
//                .size(10)
//                .build());

        adapter = new BaseRecyclerAdapter<String>(getActivity(), mdata, R.layout.simple_list_item_right) {
            @Override
            public void init(BaseRecyclerViewHolder holder, String bean, int position) {

                Logger.d(bean + "   --" + argInt);
                holder.setText(R.id.text1, bean);


            }
        };
        adapter.setOnItemClickLinster(new BaseRecyclerAdapter.OnItemClickLinster() {
            @Override
            public void onItemClick(View view, int position) {
                String type = mdata.get(position);
                Intent intent = new Intent(getActivity(), TypeActivity.class);
                intent.putExtra("type", type);
                Logger.d(type);
                startActivity(intent);
            }
        });
        recyclerView.setAdapter(adapter);//设置适配器

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
